﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace XMLCatalogue.DataModel
{
    public class CatalogueDataSource
    {
        private static CatalogueDataSource _dataSource = new CatalogueDataSource();

        public static IEnumerable<CatalogueItem> GetItems()
        {
            return _dataSource.Items;
        }

        public IEnumerable<CatalogueItem> Items {get; private set;}

        public CatalogueDataSource()
        {
            XDocument xmlCata = XDocument.Load("DataModel/Catalogue.xml");
            IEnumerable<CatalogueItem> cItems = from i in xmlCata.Descendants("Item")
                                               select new CatalogueItem(
                                                   i.Element("Name").Value, 
                                                   i.Element("Image").Value, 
                                                   i.Element("Description").Value
                                               );
            this.Items = cItems;
        }
    }
}
